<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ taskNum }}</strong></span
    >
    <ul class="filters" @click="fn">
      <li>
        <!-- 6.1 判断谁应该有高亮样式: 动态class
            6.2 用户点击要切换isSel里保存的值
         -->
        <a
          :class="{ selected: isSel == 'all' }"
          @click="isSel = 'all'"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: isSel == 'no' }"
          @click="isSel = 'no'"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: isSel == 'yes' }"
          @click="isSel = 'yes'"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clear">清除已完成</button>
  </footer>
</template>

<script>
export default {
  // 5.0 props定义 接收父传来的值
  props: ["fArr"],
  computed: {
    taskNum() {
      return this.fArr.length;
    },
  },
  data() {
    return {
      isSel: "all", // 全部:'all', 已完成'yes', 未完成'no'
    };
  },
  methods: {
    fn() {
      // 6.3 子 -> 父 把类型字符串传给App.vue
      this.$emit("changeType", this.isSel);
    },
    clear() {
      // 清空已完成任务
      // 7.1 触发App.vue里事件对应clearFun方法
      this.$emit("clear");
    },
  },
};
</script>
